﻿using Spire.Xls;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace Et2xlsx
{
    internal class Program
    {
        static void Main(string[] args)
        {
            // 筛选出后缀为 .et 的文件路径
            string[] filteredArgs = args.Where(arg =>
            {
                string extension = Path.GetExtension(arg).ToLower();
                return extension == ".et";
            }).ToArray();

            if (filteredArgs.Length > 0)
            {
                Console.WriteLine($"共有 {filteredArgs.Length} 个.et文件：");
                string saveDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + $@"\转换结果{DateTime.Now:yyyyMMddHHmmss}";
                Directory.CreateDirectory(saveDir);

                // 遍历每个命令行参数（即每个文件的路径）
                foreach (string filePath in filteredArgs)
                {
                    Console.Write("正在转换： " + filePath);
                    Workbook workbook = new Workbook();
                    workbook.LoadFromFile(filePath);
                    workbook.SaveToFile(saveDir + $@"\{Path.GetFileNameWithoutExtension(filePath)}.xlsx");
                    workbook.Dispose();
                    Console.WriteLine(" 转换完毕！");
                }

                // 等待用户输入，防止控制台窗口立即关闭
                Console.WriteLine();
                Console.WriteLine("全部转换完毕，转换文件储存在桌面“转换结果”文件夹。按任意键退出...");
                Console.ReadKey();
            }
            else
            {
                Console.WriteLine("未发现.et文件，请将.et文件拖动到图标上。");
                Console.WriteLine();
                Console.WriteLine("按任意键退出...");
                Console.ReadKey();
                return;
            }
        }
    }
}
